package unit;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import org.je.cons.JCons;
import org.je.log.JLog;
import org.je.ufo.Sleep;
import org.je.util.DynBuffer;
import org.je.util.NumberUtil;

public class makeYes
{
	public static void main(String... args) throws Exception {

		JLog.error("apple");

		long d = System.currentTimeMillis();
		for (int i = 0; i < 1000; ++i) {
			test();
		}

		System.out.println(System.currentTimeMillis() - d);

		Sleep.millis(1200);
	}

	public static void test() throws Exception {
		Socket soc = new Socket("127.0.0.1", 9999);
		OutputStream out = soc.getOutputStream();

		out.write(NumberUtil.int2bytes(11));
		out.write("fyf_eoe".getBytes());

		out.flush();

		InputStream in = soc.getInputStream();

		byte[] tem = new byte[512];
		int len = 0;
		DynBuffer bf = new DynBuffer();

		while ((len = in.read(tem)) >= 0) {
			bf.append(tem, 0, len);
			int size = NumberUtil.bytes2int(bf.array());
			if (bf.size() >= size) {
				break;
			}
		}

		out.close();

		in.close();

		JLog.info(new String(bf.array(), 4, bf.size() - 4, JCons.enc().utf8));

		soc.close();
	}
}
